package cn.mothin.vo.system;

import java.util.ArrayList;
import java.util.List;

public class PermissionTreeData {
	/**
	 * 节点类型：菜单
	 */
	public static final int MENU_PACKET = 0;
	/**
	 * 节点类型：功能模块
	 */
	public static final int MODULE = 1;
	/**
	 * 节点类型：功能项
	 */
	public static final int ITEM = 2;

	private String id;
	private String hostId;
	private String hostModuleId;
	private String parentId;
	private String name;
	private String memo;
	private String icon;
	private int ordinal;
	private boolean intChecked;
	private boolean checked;
	// 节点类型：0:菜单；1：功能模块；2：功能项
	private int nodeType;
	private String moduleId;
	private String url;
	private List<PermissionTreeData> children;

	public void addChild(PermissionTreeData data) {
		if (data == null) {
			return;
		}

		if (children == null) {
			children = new ArrayList<PermissionTreeData>();
		}

		int index = -1;
		for (int i = 0; i < children.size(); i++) {
			PermissionTreeData j = children.get(i);
			if (data.getOrdinal() <= j.getOrdinal()) {
				index = i;
				break;
			}
		}
		if (index == -1) {
			children.add(data);
		} else {
			children.add(index, data);
		}
	}

	public void addChild(List<PermissionTreeData> list) {
		if (list == null || list.size() == 0) {
			return;
		}
		if (children == null) {
			children = list;
		} else {
			children.addAll(list);
//			for (int i = 0; i < list.size(); i++) {
//				PermissionTreeData p = list.get(i);
//				addChild(p);
//			}
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public boolean isIntChecked() {
		return intChecked;
	}

	public void setIntChecked(boolean intChecked) {
		this.intChecked = intChecked;
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public int getNodeType() {
		return nodeType;
	}

	public void setNodeType(int nodeType) {
		this.nodeType = nodeType;
	}

	public List<PermissionTreeData> getChildren() {
		return children;
	}

	public void setChildren(List<PermissionTreeData> children) {
		this.children = children;
	}

	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	public String getModuleId() {
		return moduleId;
	}

	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getHostId() {
		return hostId;
	}

	public void setHostId(String hostId) {
		this.hostId = hostId;
	}

	public String getHostModuleId() {
		return hostModuleId;
	}

	public void setHostModuleId(String hostModuleId) {
		this.hostModuleId = hostModuleId;
	}

}
